﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.Diagnostics;
using System.Windows.Forms;
using ExcelAddIn.Common;
using Microsoft.Win32;

namespace ExcelAddIn
{
    public partial class Ribbon1
    {
        GZBHZ gzbhz ;//工作表
        GZBoHZ gzBoHz;//工作薄
        QiuTong qiuTong;//求同
        Login login;//登陆

        private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
        {

        }

        /// <summary>
        /// 工作表汇总
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGZBHZ_Click(object sender, RibbonControlEventArgs e)
        {
            if (gzbhz == null || gzbhz.IsDisposed)
            {
                gzbhz = new GZBHZ();
            }
            ////关联Excel窗口
            ////获取窗口句柄
            //IntPtr handel = Process.GetCurrentProcess().MainWindowHandle;
            //////得到父窗口
            //NativeWindow win = NativeWindow.FromHandle(handel);
            //gzbhz.ShowDialog(win);
            gzbhz.Show();
        }

        /// <summary>
        /// 工作薄汇总
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGZBoHZ_Click(object sender, RibbonControlEventArgs e)
        {
            if (gzBoHz == null || gzBoHz.IsDisposed)
            {
                gzBoHz = new GZBoHZ();
            }
            gzBoHz.Show();
        }

        /// <summary>
        /// 求同
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonSame_Click(object sender, RibbonControlEventArgs e)
        {
            if (qiuTong == null || qiuTong.IsDisposed)
            {
                qiuTong = new QiuTong();
            }
            qiuTong.Show();
        }

        /// <summary>
        /// 收藏夹
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonFile_Click(object sender, RibbonControlEventArgs e)
        {
            RegistryHelper rh = new RegistryHelper();
            //获取用户秘钥
            string portName = rh.GetRegistryData(Registry.LocalMachine, "SOFTWARE\\TYExcelHelper\\Params\\Account", "SecurityKey");
            //没有秘钥
            if(String.IsNullOrEmpty(portName))
            {
                if (login == null || login.IsDisposed)
                {
                    login = new Login();
                }
                login.Show();
            }
        }
    }
}
